/**
 * Terrain.java
 */

package rainingcatsdogs;

import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;

/**
 * The class that holds the state of the ground in the game. Should be able to
 * reduce health points when an enemy collides with it
 */
public class Terrain extends Sprite {

	/**
	 * The store of how many hit points that the terrain will have. This is
	 * reduced when an enemy collides with it or the turret.
	 */
	private int hitPoints;

	/**
	 * Constructor for the Terrain class. This will be called at the start of
	 * the game to create a piece of terrain that represents the bottom of the
	 * screen which you are trying to protect.
	 * 
	 * @param image
	 *            The image to use for the terrain
	 */
	public Terrain(Image image) {
		super(image, image.getWidth(), image.getHeight());

		// Initial number of hit points is 100
		this.hitPoints = 100;
	}

	/**
	 * Reduces the hit points of the terrain, if the hit points drops below 1
	 * then the terrain is destroyed.
	 * 
	 * @param damage
	 *            The amount of damage to do to the terrain
	 * @return Whether the terrain has ran out of HP
	 */
	public boolean reduceHP(int damage) {
		this.hitPoints -= damage;
		if (hitPoints < 1) {
			// this.destroy();
			return true;
		} else {
			return false;
		}
	}

	/**
	 * Resets the hit points to 100 whenever a life has been lost.
	 */
	public void resetHP() {
		this.hitPoints = 100;

	}

	/**
	 * Get the number of hit points of the terrain
	 * 
	 * @return 
	 *   The number of hit points the terrain has
	 */
	public int getHitPoints() {
		return hitPoints;
	}

}
